<template>
    <h2>录入房号</h2>
    <input type="button" value="房号列表" @click="liebikws">
    <table>
        <tr>
            <td>房间类型</td>
            <td>
                <select v-model="prose.rid">
                    <option value="">请选择</option>
                    <option :value="is.id" v-for="is in type">{{ is.rname }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>门店</td>
            <td>
                <select v-model="prose.storid">
                    <option value="">请选择</option>
                    <option :value="its.sid" v-for="its in stor">{{its.sname}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房号</td>
            <td>
                <input type="text" v-model="prose.name">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="aiwmwsssgg">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {reactive, toRefs,onMounted} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    type:[],
    stor:[],
    prose:{
        rid:'',
        storid:'',
        name:''
    }
  })
  let {type,stor,prose} =toRefs(data)

  onMounted(()=>{
    gettype()
    getstore()
  })

  const gettype=()=>{
    axios({
        url:'/api/Price/Bindtype',
        method:'get'
    })
    .then(res=>{
        type.value=res.data.data;
    })
  }

  const getstore=()=>{
    axios({
        url:'/api/Num/Bindstore',
        method:'get'
    })
    .then(res=>{
        stor.value=res.data.data;
    }
    )
  }

  const aiwmwsssgg=()=>{
    if(prose.value.rid==""){
        alert("房间类型不能为空")
        return;
    }
    if(prose.value.storid==""){
        alert("门店不能为空")
        return;
    }
    if(prose.value.name==""){
        alert("房号不能为空")
        return;
    }
    let obj={
        "rid": prose.value.rid,
  "storid": prose.value.storid,
  "nname": prose.value.name,
  "nstates": 1,
  "isdelete": false
    }
    axios({
        url:'/api/Num/Addnum',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==-2){
            alert("房号不能重复")
            return;
        }else if(res.data.data==1){
            alert("添加房号信息成功")
        }else{
            alert("添加房号信息失败")
        }
    })
  }

  const liebikws=()=>{
    router.push('shownum')
  }
  </script>
  
  <style scoped>
  
  </style>